Git Init
The first step to using Git in any project is to initialize a repository. This sets up a hidden .git
directory that tracks your changes, branches, history, and more.
What is a Repository
A repository (or repo) is a directory where Git tracks and stores versions of your files. You can initialize a new Git repository in any folder using the git init
command.
Once initialized, Git will start tracking changes in that folder — but only for files you tell it to track.
Create Your First Repository
- Open your terminal
- Navigate to a directory where you will keep your repo's
- IF you don't have one I like to use projects:
mkdir projects
- IF you don't have one I like to use projects:
cd projects
- Initialize the repository:
git init git-demo
- You should see:
Initialized empty Git repository in /your/path/git-101/.git/
- Confirm Git is now tracking the folder:
ls -a # or `dir /a` on Windows
tip
This command can be used on existing codebases or folders to track the chages of the files inside, not just new directories you create.